package com.ruoyi.btlfbreed.mapper;

import java.util.List;

import com.ruoyi.btlfbreed.domain.MyTbChickenGrowData;
import com.ruoyi.btlfbreed.domain.TbChickenGrowthRecords;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 肉鸡成长记录Mapper接口
 * 
 * @author codeman
 * @date 2024-05-07
 */
public interface TbChickenGrowthRecordsMapper 
{
    /**
     * 查询肉鸡成长记录
     * 
     * @param recordId 肉鸡成长记录主键
     * @return 肉鸡成长记录
     */
    public TbChickenGrowthRecords selectTbChickenGrowthRecordsByRecordId(Long recordId);

    /**
     * 查询肉鸡成长记录列表
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 肉鸡成长记录集合
     */
    public List<TbChickenGrowthRecords> selectTbChickenGrowthRecordsList(TbChickenGrowthRecords tbChickenGrowthRecords);

    /**
     * 新增肉鸡成长记录
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 结果
     */
    public int insertTbChickenGrowthRecords(TbChickenGrowthRecords tbChickenGrowthRecords);

    /**
     * 修改肉鸡成长记录
     * 
     * @param tbChickenGrowthRecords 肉鸡成长记录
     * @return 结果
     */
    public int updateTbChickenGrowthRecords(TbChickenGrowthRecords tbChickenGrowthRecords);

    /**
     * 删除肉鸡成长记录
     * 
     * @param recordId 肉鸡成长记录主键
     * @return 结果
     */
    public int deleteTbChickenGrowthRecordsByRecordId(Long recordId);

    /**
     * 批量删除肉鸡成长记录
     * 
     * @param recordIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTbChickenGrowthRecordsByRecordIds(Long[] recordIds);

    @Select("<script> SELECT YEAR(A.growth_date) year ,MONTH(A.growth_date) month,B.chicken_no chickenNo,MAX(A.weight) weight,MAX(A.feed_consumption) feedConsumption\n" +
        "FROM  tb_chicken_growth_records A " +
        "LEFT JOIN tb_chickens B ON A.chicken_id=B.chicken_id " +
        "WHERE YEAR(A.growth_date)=#{year}  " +
        "<if test='chickenNo != null and chickenNo != \"\"'>" +
        "  AND  B.chicken_no = #{chickenNo}" +
        "</if>" +
        " GROUP BY  YEAR(A.growth_date),MONTH(A.growth_date),B.chicken_no </script>")
    public List<MyTbChickenGrowData> getMonthSumGrowData(@Param("year") String year,@Param("chickenNo") String chickenNo);

    @Select("<script> SELECT  year , month,AVG(A.weight) weight,AVG(A.feedConsumption) feedConsumption FROM (\n" +
        "SELECT YEAR(A.growth_date) year ,MONTH(A.growth_date) month,MAX(A.weight) weight,MAX(A.feed_consumption) feedConsumption \n" +
        "        FROM  tb_chicken_growth_records A \n" +
        "        LEFT JOIN tb_chickens B ON A.chicken_id=B.chicken_id \n" +
        "        WHERE YEAR(A.growth_date)=#{year}  \n" +
        "        GROUP BY  YEAR(A.growth_date),MONTH(A.growth_date) \n" +
        "\t\t\t\t) AS A \n" +
        "\t\t\t\t GROUP BY  year,month </script>")
    public List<MyTbChickenGrowData> getMonthAvgGrowData(String year);




}
